import 'package:flutter/material.dart';

class ListViewStudy extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return _buildListViewBuilder();
  }

  Widget _buildListView() {
    return ListView(
      padding: EdgeInsets.all(10),
      children: [
        ListTile(
          contentPadding: EdgeInsets.all(10),
          leading: Icon(Icons.android),
          title: Text('Android'),
          subtitle: Text('Android'),
          trailing: Icon(Icons.add),
          onTap: () {
            print('点击了');
          },
          style: ListTileStyle.list,
        ),
        Divider(height: 1, color: Colors.red),
        ListTile(
          contentPadding: EdgeInsets.all(10),
          leading: Icon(Icons.android),
          title: Text('Android'),
          subtitle: Text('Android'),
          trailing: Icon(Icons.add),
          onTap: () {
            print('点击了');
          },
        ),
        ListTile(
          contentPadding: EdgeInsets.all(10),
          leading: Icon(Icons.android),
          title: Text('Android'),
          subtitle: Text('Android'),
          trailing: Icon(Icons.add),
          onTap: () {
            print('点击了');
          },
        ),
        ListTile(
          contentPadding: EdgeInsets.all(10),
          leading: Icon(Icons.android),
          title: Text('Android'),
          subtitle: Text('Android'),
          trailing: Icon(Icons.add),
          onTap: () {
            print('点击了');
          },
        ),
        ListTile(
          contentPadding: EdgeInsets.all(10),
          leading: Icon(Icons.android),
          title: Text('Android'),
          subtitle: Text('Android'),
          trailing: Icon(Icons.add),
          onTap: () {
            print('点击了');
          },
        ),
        ListTile(
          contentPadding: EdgeInsets.all(10),
          leading: Icon(Icons.android),
          title: Text('Android'),
          subtitle: Text('Android'),
          trailing: Icon(Icons.add),
          onTap: () {
            print('点击了');
          },
        ),
        ListTile(
          contentPadding: EdgeInsets.all(10),
          leading: Icon(Icons.android),
          title: Text('Android'),
          subtitle: Text('Android'),
          trailing: Icon(Icons.add),
          onTap: () {
            print('点击了');
          },
        ),
        ListTile(
          contentPadding: EdgeInsets.all(10),
          leading: Icon(Icons.android),
          title: Text('Android'),
          subtitle: Text('Android'),
          trailing: Icon(Icons.add),
          onTap: () {
            print('点击了');
          },
        ),
      ],
    );
  }

  List<Widget> _buildList() {
    List<Widget> list = [];
    for (int i = 0; i < 100; i++) {
      list.add(ListTile(
        contentPadding: EdgeInsets.all(10),
        leading: Icon(Icons.android),
        title: Text('Android'),
        subtitle: Text('Android'),
        trailing: Icon(Icons.add),
        onTap: () {
          print('点击了');
        },
      ));
    }
    return list;
  }

  Widget _buildListViewBuilder() {
    return ListView.builder(
      itemCount: 100, // 列表项总数
      itemBuilder: (BuildContext context, int index) {
        // 构建每个列表项的回调函数

        TextButton(
          style: TextButton.styleFrom(

            backgroundColor: Colors.red,
            side: BorderSide(),
          ),
          onPressed: () {},
          child: Text("我是按钮${index}"),
        );
        return ListTile(title: Text("我是标题${index}")); // 返回对应索引的Widget
      },
    );
  }
}
